package com.bjc.nio.c1;

import java.nio.ByteBuffer;

import static com.bjc.nio.util.ByteBufferUtil.debugAll;

/**
 * @program: nettypro
 * @description:
 * @author: bjc
 * @create: 2021-09-15 21:16
 */
public class TestByteBufferReadWrite {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        // 'a'
        buffer.put((byte)0x61);
        debugAll(buffer);
        // 'b' 'c' 'd'
        buffer.put(new byte[]{0x62,0x63,0x64});
        debugAll(buffer);
        buffer.flip();
        System.out.println(buffer.get());
        debugAll(buffer);
        //将未读完的数据往前压缩
        buffer.compact();
        debugAll(buffer);
        buffer.put(new byte[]{0x65,0x66});
        debugAll(buffer);
    }
}
